#（仅限windows系统）读取某文件中所有行，每行当作域名进行dns解析
param(
    [string]$F
)

if(-not $F){
    $F = Get-ChildItem -File | Where-Object{$_.Extension -eq ".txt"} | Select-Object -ExpandProperty FullName -First 1
    if(-not $F){
        Write-Error "当前目录下找不到任何.txt文件"
        Exit
    }
}

$names = Get-Content $F
foreach($name in $names){
    Write-Host $name.PadRight(40, '-')
    try{
        Resolve-DnsName -Name $name -DnsOnly -ErrorAction Stop  | ForEach-Object {
            if(($_.Section -eq "Answer") -and  $_.IPAddress){
                Write-Host "   $($_.IPAddress)"
            }
        }
    }catch{
        Write-Host "   解析失败" -ForegroundColor Red
    }
    Write-Host ''.PadRight(40, '-')
}